package com.learn.sunday.fegin.controller;

import com.learn.sunday.fegin.service.StockOpenFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicLong;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    private AtomicLong seq = new AtomicLong(0L);
    @Resource
    private StockOpenFeignService stockOpenFeignService;

    /**
     * 新增订单
     * @return
     */
    @RequestMapping("/addOrder")
    public String addOrder(){
        log.info("订单新增开始");
        String result = stockOpenFeignService.addStock();
        log.info("订单新增结结果:{}",result);
        //调用库存扣减
        result = stockOpenFeignService.subStock();
        log.info("第{}次库存扣减结果:{}",seq.incrementAndGet(),result);
        return "订单服务-订单新增成功:" + result;
    }

}
